﻿using prufa.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace prufa.Migrations
{
    public class GameDAL
    {
        GamesDataContext context = new GamesDataContext();
        public List<GameInstance> GetGame()
        {
            List<Game> game = context.Games.Select(a => a).ToList();
            List<GameInstance> listToReturn = new List<GameInstance>();
            foreach (var item in game)
            {
                listToReturn.Add(ParseGame(item));
            }
            return listToReturn;
        }

        public GameInstance GetGameByID(int gameId)
        {
            Game game = context.Games.Where(a => a.GameId == gameId).SingleOrDefault();
            return ParseGame(game);
        }

        private GameInstance ParseGame(Game game)
        {
            if (game != null)
            {
                GameInstance gameToReturn = new GameInstance()
                {
                    GameCategory = game.GameCategory,
                    GameId = game.GameId,
                    GameName = game.GameName,
                    MaxPlayers = game.MaxPlayers,
                    MinPlayers = game.MinPlayers,
                    PlayCounter = game.PlayCounter
                };
                return gameToReturn;
            }

            return null;
        }
    }
}